﻿using System.Collections.Generic;
using Model.DBInteractions;
using Model.EntityRepositories;
using Model.Entities;
using Model.Interfaces;

namespace Model.Services
{
    public class PageService : IPageService
    {
         private readonly IPageRepository _PageRepository;
        private readonly IUnitOfWork _unitOfWork;
        public PageService(IPageRepository PageRepository, IUnitOfWork unitOfWork)
        {
            this._PageRepository = PageRepository;
            this._unitOfWork = unitOfWork;
        }  
        #region IPageService Members

        public IEnumerable<Page> GetPages()
        {
            var Pages = _PageRepository.GetAll();
            return Pages;
        }

        public Page GetPageById(int id)
        {
            var Page = _PageRepository.GetById(id);
            return Page;
        }

        public void CreatePage(Page Page)
        {
            _PageRepository.Add(Page);
            _unitOfWork.Commit();
        }

        public void DeletePage(int id)
        {
            var Page = _PageRepository.GetById(id);
            _PageRepository.Delete(Page);
            _unitOfWork.Commit();
        }

        public void UpdatePage(Page Page)
        {
            _PageRepository.Update(Page);
            _unitOfWork.Commit();
        }

        public void SavePage()
        {
            _unitOfWork.Commit();
        }

        #endregion
    }
}
